package com.zhang.blog.controller;

import com.zhang.blog.common.aop.LogAnnotation;
import com.zhang.blog.common.cache.Cache;
import com.zhang.blog.service.ArticleService;
import com.zhang.blog.vo.ArticleVo;
import com.zhang.blog.vo.Result;
import com.zhang.blog.vo.params.ArticleParam;
import com.zhang.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName: ArticleController
 * @Auther: dell
 * @Date: 2021/10/27 20:46
 * @Description:
 */
@RestController
@RequestMapping("articles")
//TODO 文章编辑没做
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    //Result是统一结果返回
    //加上此注解，代表要对此接口记录日志
    @LogAnnotation(module="文章",operation = "获取文章列表")
    @Cache(expire = 5*60*1000,name = "articles")
    @PostMapping
    public Result articles(@RequestBody PageParams pageParams) {
        //ArticleVo 页面接收的数据
        return  articleService.listArticle(pageParams);
    }

    @PostMapping("hot")
    @Cache(expire = 5*60*1000,name = "hot_article")
    public Result hotArticles(){
        int limit =6;
        return articleService.hotArticles(limit);
    }
    @PostMapping("new")
    @Cache(expire = 5*60*1000,name = "newArticles")
    public Result newArticles(){
        int limit = 5;
        return articleService.newArticles(limit);
    }
    @PostMapping("listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }
    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }
    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }


}
